﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 异常02
{
    class Program
    {
        static void Main(string[] args)
        {
            //Login(123, "123");
            try
            {
                // Login(123, "bcd");
                Login(123, "abc");
            }
            //catch (Exception)
            //{
            //    Console.WriteLine("输入有误");
            //}
            //catch (DivideByZeroException e)
            //{
            //    Console.WriteLine("/0");
            //}
            //catch (MyException e)
            //{
            //    Console.WriteLine("输入有误");
            //}
            catch(Exception e)
            {
                Console.WriteLine(e.GetType().Name);
            }
            finally // 不管有没有捕获异常，都会执行的代码块
            {
                Console.WriteLine("全剧终");
            }
        }

        public static void Login(int id, string psw)
        {
            if (id == 123 && psw == "abc")
            {
                Console.WriteLine("登录成功");
            }
            else
            {
                MyException me = new MyException("登录失败");
                throw me;
            }
        }
    }

    class MyException : Exception
    {
        public MyException(string message) : base(message)
        {
            Console.WriteLine(message);
        }
    }
}
